<?php

namespace Drupal\shusy_store_order\ViewsController;

use Drupal\shusy_store_order\ViewsController\handler\field\ShusyStoreOrderEditLinkViewsField;
use Drupal\shusy_store_order\ViewsController\handler\field\ShusyStoreOrderLinesViewsField;
use Drupal\shusy_store_order\ViewsController\handler\field\ShusyStoreOrderStatusViewsField;
use Drupal\shusy_store_order\ViewsController\handler\field\ShusyStoreOrderTotalViewsField;
use Drupal\shusy_store_order\ViewsController\handler\field\ShusyStoreOrderTypeViewsField;
use Drupal\shusy_store_order\ViewsController\handler\filter\ShusyStoreOrderStatusViewsFilter;
use Drupal\shusy_store_order\ViewsController\handler\filter\ShusyStoreOrderTypeViewsFilter;
use EntityDefaultViewsController;


class ShusyStoreOrderViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $revision_table = $this->info['revision table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyStoreOrderEditLinkViewsField::class,
        ],
      ];
      $info[$table]['total'] = [
        'title' => '总价',
        'help' => '总价',
        'real field' => 'total',
        'field' => [
          'handler' => ShusyStoreOrderTotalViewsField::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 取消 1 购物车 2 待支付 3 待发货 4 待收货 5 待评价 6 已完成 7 未提交',
        'help' => '状态 0 取消 1 购物车 2 待支付 3 待发货 4 待收货 5 待评价 6 已完成 7 未提交',
        'real field' => 'status',
        'field' => [
          'handler' => ShusyStoreOrderStatusViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreOrderStatusViewsFilter::class,
        ],
      ];
      $info[$table]['lines'] = [
        'title' => t('订单项'),
        'help' => t('订单项.'),
        'field' => [
          'handler' => ShusyStoreOrderLinesViewsField::class,
          'type' => 'list<shusy_store_order_line>',
        ],
      ];
      $info[$table]['type'] = [
        'title' => '订单类型 0 正常 1 拼团 2 秒杀',
        'help' => '订单类型 0 正常 1 拼团 2 秒杀',
        'real field' => 'type',
        'field' => [
          'handler' => ShusyStoreOrderTypeViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreOrderTypeViewsFilter::class,
        ],
      ];
      $info[$revision_table]['type'] = [
        'title' => '订单类型 0 正常 1 拼团 2 秒杀',
        'help' => '订单类型 0 正常 1 拼团 2 秒杀',
        'real field' => 'type',
        'field' => [
          'handler' => ShusyStoreOrderTypeViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreOrderTypeViewsFilter::class,
        ],
      ];
      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
